package game.fury;

import android.graphics.Canvas;
import android.graphics.Paint;
import sheep.game.Game;
import sheep.game.Sprite;
import sheep.game.State;
import sheep.graphics.Font;
import sheep.graphics.Image;
import sheep.gui.TextButton;
import sheep.gui.WidgetAction;
import sheep.gui.WidgetListener;
import sheep.input.TouchListener;

/**
 *	This class makes the intro screen with two text buttons for level 1 and 2
 * @author Marius Haugen
 */
public class IntroScreen extends State implements TouchListener, WidgetListener {
	
	private World world;
	private Image backgroundImage = new Image(R.drawable.welcome_400x800);
	
	private Sprite background;
	private TextButton randomLevel;
	private TextButton normalMode;
	private TextButton instructions;
	private TextButton quit;
	
	/**
	 *  Creates a introscreen, with textbuttons. This state is never pop'ed, and is always on the top of the state stack
	 * @param game The game object
	 * @param world A world object (only used when closing the program) 
	 */
	public IntroScreen(Game game, World world){
		
		this.world = world;
		background = new Sprite(backgroundImage);
		background.setShape(300, 480);
		background.setPosition(240, 400);
		
		
		normalMode = new TextButton(160, 400, "Play normal game", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20});
		addTouchListener(normalMode);
		normalMode.addWidgetListener(this);
		
		randomLevel = new TextButton(130, 500, "Random generated level", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20});
		addTouchListener(randomLevel);
		randomLevel.addWidgetListener(this);
		
		instructions = new TextButton(180,600, "Instructions", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20});
		addTouchListener(instructions);
		instructions.addWidgetListener(this);
		
		quit = new TextButton(200, 700, "Quit game", new Paint[] {Font.WHITE_SANS_BOLD_20, Font.WHITE_SANS_BOLD_20});
		addTouchListener(quit);
		quit.addWidgetListener(this);

	}
	
	public void draw(Canvas canvas){
		background.draw(canvas);
	
		randomLevel.draw(canvas);
		normalMode.draw(canvas);
		
		instructions.draw(canvas);
		
		quit.draw(canvas);
	}
	
	public void update(float dt){
		background.update(dt);
	}
	

	/**
	 * Listens for touchinput on the textbuttons 
	 */
	@Override
	public void actionPerformed(WidgetAction action) {
		
		// call FuryScreen with type set to 1 to get normal game
		if(action.getSource() == normalMode){
			getGame().pushState(new FuryScreen(getGame(),1,0));
		}
		
		// call FuryScreen with type set to 0 to get random level
		if(action.getSource() == randomLevel){
			getGame().pushState(new FuryScreen(getGame(),0,0));
		}
		
		if(action.getSource() == instructions){
			getGame().pushState(new InstructionScreen());
		}
		
		if(action.getSource().equals(quit)){
			world.quit();
		}

	}

}
